<?php

//发现控制器
class Found extends Controller {

	function Found()
	{
		parent::Controller();	
		$this->load->model("accounts_model", "am");
		$this->load->model("site_model", "sm");
		$this->load->model("classes_model", "cm");
		//登陆状态检测
		$this->userid = $this->am->is_logined();
		$this->account = $this->am->get_account();
	}
	
	function index()
	{
		//参数处理(非法ID检测)
		if(!$classid = u(2)) $classid = 0;
		if(!$subclassid = u(3)) $subclassid = 0;
		
		//输出公共header
		if(!isset($pagedata["title"])) $pagedata["title"] = "发现轻站 | 热闹网";
		if(!isset($pagedata["keywords"])) $pagedata["keywords"] = "热闹、热闹网、热闹100、renao、renao100、轻网站、网站、小站、微网站、博客、社区、互动";
		if(!isset($pagedata["description"])) $pagedata["description"] = "热闹网(www.renao100.com) - 前所未有的互动轻网站社区。轻网站是一个创意点子的实现，每个人拥有属于自己的轻网站，并且允许共同维基创建内容。适合个人站、兴趣站、才艺站、组织站甚至官方站。轻网站可以是WEB1.0，更可以是WEB2.0。";
		$this->autoload_model->output_header($pagedata);
		//获取当前分类
		$currentclass = array();
		$currentscount = 0;
		if ($classid > 0) {
			$currentclass = $this->cm->get($classid);
			$currentscount = $this->cm->count_class_site(array($classid));
		}
		$viewdata['currentclass'] = $currentclass;
		$viewdata['currentscount'] = $currentscount;
		
		if($subclassid > 0) {//子类小站列表
			$sortid = u(4);
			if(!$sortid) $sortid = 1;
			$per_page = 20;
			$offset = u(5);
			$subclass = $this->cm->get($subclassid);
			$subscount = $this->cm->count_class_site(array($subclassid));
			$sites = $this->cm->get_sort_class_site($subclassid, $per_page, $offset, $sortid);
			
			//分页处理
			$base_url = '/found/'.$classid.'/'.$subclassid.'/'.$sortid;
			$total_rows = $subscount;
			$pagestring = pages($base_url,$total_rows,5,$per_page);
			$viewdata["offset"] = $offset;
			$viewdata["pagestring"] = $pagestring;
			
			$viewdata['sites'] = $sites;
			$viewdata['subclass'] = $subclass;
			$viewdata['subscount'] = $subscount;
			$this->load->view(__CLASS__.'/show', $viewdata);
		} else {
			//获取分类
			($classid > 0) ? $limit = 999 : $limit = 4;
			$classes = $this->cm->get_found_class($classid, $limit);
//			a($classes);
			$viewdata['classes'] = $classes;
			if ($classid > 0) {//子类列表
				$this->load->view(__CLASS__.'/list', $viewdata);
			} else {//默认列表
				
				//人气热站 - 随机取9个
				$hotsites = $this->sm->rand_hot_site(9);
				//新张热站 - 随机取9个
				$newsites = $this->sm->rand_new_site(9);
				
				$viewdata['hotsites'] = $hotsites;
				$viewdata['newsites'] = $newsites;
				$this->load->view(__CLASS__.'/index', $viewdata);
			}
		}
		
		//输出公共footer
		$this->autoload_model->output_footer();
	}
	
	
}

/* End of file */